import { Config } from "../../Config"
import { Player } from "../core/Player"
import Utils from "../GameUtils"
import { 野马 } from "../evolution/野马"
import { BaseHandler } from "./BaseHandler"

export class 野马Handler extends BaseHandler{

    /** 跃踏
     *  不能攻击小子和核心
     */
    impact(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_野马_IMPACT)
        let startPoint = this.gameMgr.map_point.get(data.start)
        let endPoint = this.gameMgr.map_point.get(data.end)
        let big_start = startPoint.big
        big_start.actionOnce()
        let small = endPoint.small
        let big_end = endPoint.big
        if(small != null) {
            //小子被攻击
            small.die(player)
        } else if(big_end != null) {
            //大子被攻击
            if(big_end.attacked(player)){
                //打过了
            } else {
                //攻击没打过，自己死亡
                big_start.die(player,endPoint.id)
                return
            }
        }
        //没有大子，就是移动
        startPoint.big = null
        endPoint.big = big_start
        big_start.point = endPoint
        this.gameMgr.sendBroadcast(Utils.getObj("野马_践踏",{"start":data.start,"end":data.end}))
        big_start.terrainAdapt()
    }
}